package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserDuoBaoYuLan;

public class DuoBaoExpandAdapter extends BaseExpandableListAdapter {
    private Context context;
    private UserDuoBaoYuLan user;
    private String[] names;
    private String[] names0 = {"40石魂", "100石魂", "200石魂", "250石魂","500石魂","1000石魂"};
    private String[] names1 = {"1000金币", "2000金币", "5000金币", "10000金币"};
    private String[] names2 = {"一级灵石*100", "二级灵石*100", "三级灵石*100", "四级灵石*100", "五级灵石*100",
            "六级灵石*100", "七级灵石*100", "八级灵石*100", "九级灵石*100", "十级灵石*100"};
    public DuoBaoExpandAdapter(Context context) {
        this.context = context;
        names=names1;
    }

    public UserDuoBaoYuLan getList() {
        return user;
    }

    public void setList(UserDuoBaoYuLan user,int num) {
        this.user = user;
        switch (num){
            case 0:
                names=names0;
                break;
            case 1:
                names=names1;
                break;
            case 2:
                names=names2;
                break;
        }
        notifyDataSetChanged();
    }

    @Override
    public int getGroupCount() {
        return names.length;
    }

    @Override
    public int getChildrenCount(int i) {
        return user.getDuoBao().get(i).getDuobao().size();
    }

    @Override
    public Object getGroup(int i) {
        return names[i];
    }

    @Override
    public Object getChild(int i, int i1) {
        return user.getDuoBao().get(i).getDuobao().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.expand_1, null);
        ViewHolder1 viewHolder1 = new ViewHolder1(view);
        viewHolder1.tvName.setText(names[i]);
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.expand_1_1, null);
        ViewHolder2 viewHolder2 = new ViewHolder2(view);
        viewHolder2.tvName.setText("单次消耗:"+user.getDuoBao().get(i).getDuobao().get(i1).getOneNumber());
        viewHolder2.tvSydj.setText("已有:"+user.getDuoBao().get(i).getDuobao().get(i1).getNowNumber());
        viewHolder2.tvHuafei.setText("共需:"+user.getDuoBao().get(i).getDuobao().get(i1).getAllNumber());
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }


    class ViewHolder1 {
        public View rootView;
        public TextView tvName;

        public ViewHolder1(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
        }

    }

    class ViewHolder2 {
        public View rootView;
        public TextView tvName;
        public TextView tvSydj;
        public TextView tvHuafei;

        public ViewHolder2(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvSydj = (TextView) rootView.findViewById(R.id.tvSydj);
            this.tvHuafei = (TextView) rootView.findViewById(R.id.tvHuafei);
        }

    }
}
